package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysApply;
import com.ruoyi.project.system.domain.SysType;
import com.ruoyi.project.system.service.ISysApplyService;

import com.ruoyi.project.system.service.ISysTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/mobileUser/apply/")
public class UserApplyController {

    @Autowired
    private ISysApplyService sysApplyService;

    @Autowired
    private ISysTypeService sysTypeService;

    /**
     * 申请入驻工人
     */
    @PostMapping("applyUser")
    public AjaxResult apply(@RequestBody SysApply sysApply) {
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysApply.setMobileUserId(mobileUserId);
        sysApply.setStatus("0");
        sysApplyService.insertSysApply(sysApply);
        return AjaxResult.success("恭喜你,提交成功............");
    }


    /**
     * 用户查看审核是否通过
     */
    @GetMapping("queryApplyUser")
    public AjaxResult queryApplyUser(SysApply sysApply) {
        Long mobileUserId = SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId();
        sysApply.setMobileUserId(mobileUserId);
        return AjaxResult.success(sysApplyService.queryApplyList(sysApply));
    }

    /**
     * 用户端显示服务类型——————
     */
    @SignatureValidation
    @GetMapping("queryParentList")
    public AjaxResult queryParentList() {
        List<SysType> sysTypes = sysTypeService.queryParentName();
        List<SysType> list=new ArrayList<>();
        for (int i = 0; i < sysTypes.size(); i++) {
            if ("热门服务".equals(sysTypes.get(i).getTypeName())){
                list.add(0,sysTypes.get(i));
            }else {
                list.add(sysTypes.get(i));
            }
        }
        return AjaxResult.success(list);
    }
}
